import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.header import Header

user="heqiang@dcax.com"
password="heqiang123!"
smtpserver=""


def addimg(resrc,imgid):
    fp=open(resrc,"rb")
    msgImage=MIMEImage(fp.read())
    fp.close()
    msgImage.add_header("Content-ID",imgid)
    return msgImage

def sendemail(resrc,file=None,img=None):
    msg=MIMEMultipart("related")
    msgtext=MIMEText(resrc,"html","utf-8")
    msg.attach(msgtext)

    msg["From"]=user
    msg["To"]="wanggeceshi"
    msg["Subject"]=Header("【通知】冒烟自动化测试报告","utf-8")

    if file != None:
        att1=MIMEApplication(open(file,"rb").read())
        att1["Content-Type"]="application/octet-stream"
        att1.add_header("Content-Disposition","attachment",filename="result.log")
        msg.attach(att1)
    if img:
        img1=MIMEImage(open(img,"rb").read(), _subtype="octet-stream")
        img1.add_header("Content-ID","image1")
        msg.attach(img1)

    smtpobj=smtplib.SMTP("172.16.5.64",25)
    tO_list=["heqiang@dcax.com","xujiangyan@dcax.com","liuyue@dcax.com"]
    smtpobj.sendmail(user,tO_list,msg=msg.as_string())

if __name__ == "__main__":
    pass







